const {
  MemberModel
} = require('../../../utils/member-model.js');
var utils =
  require("../../../utils/util.js");
var memberModel = new MemberModel();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    monthAdd: 0, //本月新增积分
    monthExpire: 0, //本月即将失效积分
    currentIntegral: 0, //当前积分
    accumulativeIntegral: 0, //累计积分
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },
  //跳转到积分明细
  goIntegralDetail() {
    wx.navigateTo({
      url: '/pages/memberCenter/integralDetail/index'
    })
  },

  /**
   * 会员资产详情
   */
  getUserAssetDetail(type) {
    var param = {};
    param.merchantId = wx.getStorageSync('merchantId');
    param.assetType = type; //可用积分
    param.statistics = true; //是否查询统计数据
    param.assetStatus = 0; //0:正常 3:过期
    memberModel.userAssetDetail(param).then(data => {
      var that = this;
      if (type == 9) {
        that.setData({
          monthAdd: utils.formatCurrency(data.monthAdd) || 0, //本月新增积分
          monthExpire: utils.formatCurrency(data.monthExpire) || 0, //本月即将失效积分
          currentIntegral: utils.formatCurrency(data.assetAvail) || 0, //当前积分
        })
      } else if (type == 10) {
        that.setData({
          accumulativeIntegral: utils.formatCurrency(data.assetAvail) || 0, //累计积分
        })
      }

    }).catch(err => {
      wx.showToast({
        title: `${err.error}`,
        icon: 'none',
        duration: 2000
      })
    })
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getUserAssetDetail(9); //,9:可用积分,10:累计积分
    this.getUserAssetDetail(10); //,9:可用积分,10:累计积分
  },

})